<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录注册页</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <style>
        .container{
            margin-top: 50px;
        }
        input:-webkit-autofill,
        input:-webkit-autofill:hover,
        input:-webkit-autofill:focus,
        input:-webkit-autofill:active {
            -webkit-transition-delay: 9999s;
            -webkit-transition: color 9999s ease-out, background-color 9999s ease-out;
        }
    </style>
</head>
<body>
<div class="container">
    <form class="form-horizontal" role="form">
        <div class="form-group">
            <label for="firstname" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" id="username" placeholder="请输入用户名">
            </div>
        </div>
        <div class="form-group">
            <label for="lastname" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-6">
                <input type="password" class="form-control" id="password" placeholder="请输入密码">
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default denglu">登录</button>
                <button type="button" class="btn btn-default zhuce">注册</button>
            </div>

        </div>
    </form>
</div>


</body>
</html>
<script>
    $(function () {
        $(".zhuce").click(function () {
            $username = $("#username").val();
            $password = $("#password").val();
            $.post("http://localhost/workspace/2018/tp5/public/register",{'username':$username,'password':$password},function (data) {
                console.log(data);
                if(data==1){
                    alert("注册成功！");
                    history.go();
                }
                else if(data==2){
                    alert("用户名已存在！");
                }
            });

        });



        $(".denglu").click(function () {
            $username = $("#username").val();
            $password = $("#password").val();
            $.post("http://localhost/workspace/2018/tp5/public/login",{'username':$username,'password':$password},function (data) {
                if(data==0){
                    alert("用户名或者密码不存在！");
                    return;
                }
                if(data==1){
                    location.href="http://localhost/workspace/2018/tp5/public/showUser";
                }

            });

        });


    });
</script>
